<template>
    <el-container>
        <el-header>
            <div class="left-panel">
                <el-button type="primary" icon="el-icon-plus" v-auth="'auction.create'" @click="create"></el-button>
                <el-button type="danger" plain icon="el-icon-delete" v-auth="'auction.delete'" v-if="selection.length>0" :disabled="selection.length==0" @click="dels"></el-button>
            </div>
            <div class="right-panel">
                <div class="right-panel-search">
                    <el-input v-model="search" placeholder="搜索" @clear="this.$TABLE.searchSubmit(this)" clearable></el-input>
                    <el-button type="primary" icon="el-icon-search" @click="this.$TABLE.searchSubmit(this)"></el-button>
                    <imiFilterBar :options="options" @filterChange="filterChange"></imiFilterBar>
                </div>
            </div>
        </el-header>
        <el-main class="nopadding">
            <scTable ref="table" row-key="id" :apiObj="apiObj" :params="params" @selection-change="selectionChange" @cell-dblclick="doubleClick" stripe remoteSort remoteFilter>
                <el-table-column type="selection" width="50"></el-table-column>
                <el-table-column label="id" prop="id" >
                                    
				</el-table-column>
                <el-table-column label="拍卖名称" prop="title" >
                                    
				</el-table-column>
                <el-table-column label="店铺id" prop="store_id" >
                    <template #default="scope"  >
                    <el-tag >{{dataList[scope.row.store_id]}} </el-tag>
                    </template>                  
				</el-table-column>
                <el-table-column label="拍卖类型" prop="type_status" >
                    <template #default="scope">
                    <el-tag :type="scope.row.type_status == 1 ? 'success' : scope.row.type_status == 2?'danger': scope.row.type_status == 3?'info':'warning'">{{type_status_option[scope.row.type_status]}}</el-tag>
                    </template>          
				</el-table-column>
                <el-table-column label="申请状态" prop="apply_status" >
                    <template #default="scope">
                    <el-tag :type="scope.row.apply_status == 1 ? 'success' : scope.row.apply_status == 2?'danger': scope.row.apply_status == 3?'info':'warning'">{{apply_status_option[scope.row.apply_status]}}</el-tag>
                    </template>    
				</el-table-column>
                <el-table-column label="开始类型" prop="start_status" >
                    <template #default="scope">
                    <el-tag :type="scope.row.start_status == 1 ? 'success' : scope.row.start_status == 2?'danger': scope.row.start_status == 3?'info':'warning'">{{start_status_option[scope.row.start_status]}}</el-tag>
                    </template>   
				</el-table-column>

                <el-table-column label="状态" prop="status" >
                    <template #default="scope">
                    <el-tag :type="scope.row.status == 1 ? 'info' : scope.row.status == 2?'danger': scope.row.status == 3?'success':scope.row.status == 7?'success':'warning'">{{status_option[scope.row.status]}}</el-tag>
                    </template>   
				</el-table-column>

                <el-table-column label="开拍报名人数" prop="enroll_num" >
                                    
                </el-table-column>
                <el-table-column label="商品" prop="goods_id" >
                                    
				</el-table-column>
                <el-table-column label="商品规格" prop="goods_sku_price_ids" >
                                    
				</el-table-column>
                <el-table-column label="起拍价格" prop="start_price" >
                                    
				</el-table-column>
                <el-table-column label="最低价格(保留价)" prop="minimum_price" >
                                    
				</el-table-column>
                <el-table-column label="加价幅度" prop="plus_price" >
                                    
				</el-table-column>
                <el-table-column label="买家保证金" prop="buyer_surety" >
                                    
				</el-table-column>
                <el-table-column label="出局贝壳补贴" prop="out_perk_shell" >
                                    
				</el-table-column>
                <el-table-column label="报名出局贝壳补贴" prop="enroll_out_perk_shell" >
                                    
				</el-table-column>
                <el-table-column label="报名需要积分" prop="enroll_score" >
                                    
				</el-table-column>
                <el-table-column label="入场积分" prop="admission_score" >
                                    
				</el-table-column>
                <el-table-column label="最高成交价" prop="max_price" >
                                    
				</el-table-column>
                <el-table-column label="最低成交价" prop="min_price" >
                                    
				</el-table-column>
                <el-table-column label="预展示多少s" prop="advance_show_s" >
                                    
				</el-table-column>
                <el-table-column label="结束时长" prop="end_s" >
                                    
				</el-table-column>
                <el-table-column label="开始时间" prop="start_time"  align="right" width="180" :formatter="this.$TABLE.datetime">
                                    
				</el-table-column>
                <el-table-column label="结束时间" prop="end_time"  align="right" width="180" :formatter="this.$TABLE.datetime">
                                    
				</el-table-column>
                <el-table-column label="几个周期" prop="cycle" >
                                    
				</el-table-column>
                <el-table-column label="发货模板" prop="dispatch_ids" >
                                    
				</el-table-column>
                <el-table-column label="创建时间" prop="createtime"  align="right" width="180" :formatter="this.$TABLE.datetime">
                                    
				</el-table-column>

                <el-table-column label="自动状态" prop="auto_status" >
                                    
				</el-table-column>
       
                <el-table-column label="第几个周期" prop="how_cycle" >
                                    
				</el-table-column>
                <el-table-column label="预展示id" prop="auction_advance_show_id" >
                                    
				</el-table-column>
                <el-table-column label="结束时间id" prop="auction_end_id" >
                                    
				</el-table-column>
                <el-table-column label="改价费" prop="change_price" >
                                    
				</el-table-column>
                
                <el-table-column label="操作" fixed="right" align="right" width="140">
                    <template #default="scope">
                        <el-button type="text" v-auth="'auction.update'" size="small" @click="update(scope.row)">编辑
                        </el-button>
                        <el-popconfirm title="确定删除吗？" @confirm="del(scope.row)">
                            <template #reference>
                                <el-button type="text" v-auth="'auction.delete'" size="small">删除</el-button>
                            </template>
                        </el-popconfirm>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
    </el-container>
    <save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save=false"></save-dialog>
</template>
<script>
    import saveDialog from './save';
    import imiFilterBar from '@/components/imiFilterBar';
    export default {
        name: 'auction',
        components: {
            saveDialog,
            imiFilterBar
        },
        data() {
            return {
                options: [
                    {
                        label: 'id',
                        value: 'id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '拍卖名称',
                        value: 'title',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '店铺id',
                        value: 'store_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '拍卖类型',
                        value: 'type_status',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '开始类型',
                        value: 'start_status',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '商品',
                        value: 'goods_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '商品规格',
                        value: 'goods_sku_price_ids',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '起拍价格',
                        value: 'start_price',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '最低价格(保留价)',
                        value: 'minimum_price',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '加价幅度',
                        value: 'plus_price',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '买家保证金',
                        value: 'buyer_surety',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '出局贝壳补贴',
                        value: 'out_perk_shell',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '报名出局贝壳补贴',
                        value: 'enroll_out_perk_shell',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '报名需要积分',
                        value: 'enroll_score',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '入场积分',
                        value: 'admission_score',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '最高成交价',
                        value: 'max_price',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '最低成交价',
                        value: 'min_price',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '预展示多少s',
                        value: 'advance_show_s',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '结束时长',
                        value: 'end_s',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '开始时间',
                        value: 'start_time',
                        type: 'datetimerange',
                        operator: 'between',
                    },
					{
                        label: '结束时间',
                        value: 'end_time',
                        type: 'datetimerange',
                        operator: 'between',
                    },
					{
                        label: '几个周期',
                        value: 'cycle',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '发货模板',
                        value: 'dispatch_ids',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '创建时间',
                        value: 'createtime',
                        type: 'datetimerange',
                        operator: 'between',
                    },
					{
                        label: '更新时间',
                        value: 'updatetime',
                        type: 'datetimerange',
                        operator: 'between',
                    },
					{
                        label: '删除时间',
                        value: 'deletetime',
                        type: 'datetimerange',
                        operator: 'between',
                    },
					{
                        label: '申请状态',
                        value: 'apply_status',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '自动状态',
                        value: 'auto_status',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '状态',
                        value: 'status',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '第几个周期',
                        value: 'how_cycle',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '预展示id',
                        value: 'auction_advance_show_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '结束时间id',
                        value: 'auction_end_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '改价费',
                        value: 'change_price',
                        type: 'text',
                        operator: '=',
                    },
					                    
                ],
                dialog: {
                    save: false
                },
                apiObj: this.$API.auction.read,
                selection: [],
                search: '',
                params:{},
                type_status_option:{"1":"贝壳竞拍","2":"降价拍","3":"升价拍","4":"暗拍(降价拍)","5":"暗拍(升价拍)"},
				start_status_option:{"time":"时间","number":"人数"},
				apply_status_option:{"1":"待审核","2":"通过","3":"拒绝"},
				auto_status_option:{"1":"非自动","2":"自动"},
				status_option:{"1":"待展示","2":"预展示","3":"进行中","5":"结束","6":"已下架","7":"流拍"},
                dataList:[],
            }
        },
        created() {
            this.$TABLE.setFilterValue(this);
            this.getdataList();
        },
        mounted() {
            
        },
        methods: {
            async getdataList(){
                var res = await this.$API.store.read.get({page: 1,pageSize: 999999})
                var list = res.data.list;
                var cate = [];
                for (let index = 0; index < list.length; index++) {
                    cate[list[index].id] = list[index].id+'👉'+list[index].name;                    
                }
                console.log(cate);
                this.dataList = cate;
            },
            doubleClick(row) {
                this.update(row);
            },
            filterChange(data) {
                this.$TABLE.filter(data, this);
            },
            create() {
                this.dialog.save = true
                this.$nextTick(() => {
                    this.$refs.saveDialog.open()
                })
            },
            update(row) {
                this.dialog.save = true
                this.$nextTick(() => {
                    this.$refs.saveDialog.open('update').setData(row)
                })
            },
            async del(row) {
                var res = await this.$API.auction.delete.post({ids: row.id});
                if (res.code == 200) {
                    this.$refs.table.refresh()
                    this.$message.success(res.message)
                } else {
                    this.$alert(res.message, "提示", {type: 'error'})
                }
            },
            async dels() {
                if (!this.selection.length) {
                    this.$message.warning("请选择要删除的数据")
                    return false;
                }
                var ids = [];
                for (const i in this.selection) {
                    ids.push(this.selection[i].id)
                }
                this.$confirm(`确定删除选中的 ${this.selection.length} 项吗？`, '提示', {
                    type: 'warning'
                }).then(() => {
                    const loading = this.$loading();
                    this.$API.auction.delete.post({ids:ids}).then(res => {
                        if (res.code == 200) {
                            this.$refs.table.refresh()
                            this.$message.success(res.message)
                        } else {
                            this.$message.error(res.message)
                        }
                        loading.close();
                    });
                })
            },
            selectionChange(selection) {
                this.selection = selection;
            },
            handleSuccess() {
                this.$refs.table.refresh()
            }
        }
    }
</script>